package com.yy.controller;

import com.alibaba.fastjson.JSON;
import com.yy.model.Users;
import com.yy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author
 * @date 2021/11/26/15:49
 */
@RestController
public class PublicController {

    @Autowired
    private UserService userService;

    @RequestMapping("/public/findAllUsers")
    public String findAllUsers(Model model) {
        System.out.println("controller被调用");
        //此时未配置mybatis 即测试用
        List<Object> allUsers = userService.findAllUsers();
        model.addAttribute("msg","successful");
        return "list";
    }

    @RequestMapping("/public/findUserById/{id}")
    public String findUserByID(@PathVariable("id") Integer id){
        System.out.println("controller层findUserById被调用");
        Users byID = userService.findByID(id);
        return JSON.toJSONString(byID);
    }
}
